package com.yj.music_center.callback.impl;

import com.yj.music_center.callback.Callback;
import com.yj.music_center.util.log.Logger;

import io.flutter.plugin.common.EventChannel;

public class CallbackImpl implements Callback {
    private static final String TAG = CallbackImpl.class.getName();

    private EventChannel.EventSink eventSink;

    private static Callback callback;
    public static Callback getInstance(){
        if(callback == null){
            synchronized (Callback.class){
                callback = new CallbackImpl();
            }
        }
        return callback;
    }

    @Override
    public void onPlaybackConfigChanged(boolean isMusicOn) {
        send2Flutter(isMusicOn);
    }

    private void send2Flutter(Object object){
        if(eventSink == null){
            Logger.d(TAG, "eventSink is null");
            return;
        }
        eventSink.success(object);
    }

    public void setEventSink(EventChannel.EventSink eventSink) {
        this.eventSink = eventSink;
    }
}
